package ufabc.edu.va.agenteminhoca;


public class Chromosome {
	static final int seeWall=0, seeEater=1, seeSpace=2, seePlant=3;

	private byte[][] newState = new byte[16][4];
	private byte[][] whatToDo = new byte[16][4];
	
	
	public byte getNewState(int i, int j) {
		return newState[i][j];
	}

	public byte getWhatToDo(int i, int j) {
		return whatToDo[i][j];
	}

	void randomize() {
		for (int i = 0; i < 16; i++) {
			for (int j = seeWall; j <= seePlant; j++) {
				newState[i][j] = (byte)(Math.random()*16);
				whatToDo[i][j] = (byte)(Math.random()*4);
			}
		}
	}
	
	void mutate (double prob) {
			for (int i = 0; i < 16; i++)
				for (int j = seeWall; j <= seePlant; j++) {
					if (Math.random() < prob)
						this.newState[i][j] = (byte)(Math.random()*16);
					if (Math.random() < prob)
						this.whatToDo[i][j] = (byte)(Math.random()*4);
				}
	}
	void crossWith(Chromosome c) {
		int crossPoint = (int)(Math.random()*128);
		byte temp;
		int ct = 0;
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 4; j++) {
				if (ct > crossPoint) {
					temp  = newState[i][j];
					newState[i][j] = c.newState[i][j];
					c.newState[i][j] = temp;
				}
				ct++;
				if (ct > crossPoint) {
					temp  = whatToDo[i][j];
					whatToDo[i][j] = c.whatToDo[i][j];
					c.whatToDo[i][j] = temp;
				}
				ct++;
			}
		}
	}
	
	public void copy(Chromosome c) {
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 4; j++) {
				this.whatToDo[i][j] = c.whatToDo[i][j];
				this.newState[i][j] = c.newState[i][j];
			}
		}
	}
}